<?php
/**
 * 获取商品
 *
 * @author hzjsq@msn.com
 * @version 01.
 */
$argv[1]=	'';
$argv[2] = '2010-01-01 23:59:59';
$argv[3] = '2010-12-01 23:59:59';

 
$sDate = time()-86400;

$eDate =  time();


define('COMMAND_MODE', true);

set_time_limit(0);

define('LIB_DIR', dirname(__FILE__) . '/lib/');

require_once(LIB_DIR . 'api/taobao/order.php');
require_once(LIB_DIR . 'api/qinqinbabycom/goods.php');
require_once(dirname(__FILE__) . '/lib/init.php');

$goodsRst = new tools_api_qinqinbabycom_goods();//taobao订单

$bn=$_GET['bn'];
 $goods = $goodsRst->fetchGoods($sDate, $eDate,$bn);
// $goods1='{"rsp":"succ","res":"","data":[{"cate_name": "奶粉","Product_IsNoStock": "1","bn": "434232320","barcode": "434232320","ibn": "434232320","brand": "伊小利","product_name": "幼儿奶粉","spec": "","product_weight": "500","product_unit": "罐"}]}';
// $goods=json_decode($goods1,1);
//var_dump($goods);


echo "There are  {" .count($goods['data'])."} goods\n";
foreach ($goods['data'] as $g) {

	//$orderOme = $orderObj->getFullTrade($tid);
	//var_dump($orderOme);
	if (!empty($g)) {
//var_dump($orderOme);
		$rt = insertIntoGoods($g, "1112212");
		if($rt){
		
			echo "{$g['bn']} done.\n";
		}else 
		{
			echo "{$g['bn']} fail.\n";
			
		}
		
	}

	
}


/**
 * 插入商品数据
 * @param array $sdf 商品数据
 * @param array $nodeId 商铺节点
 */
function insertIntoGoods($sdf, $nodeId) {

	static $goodsObj = null;
	static $response = null;

	if (!$goodsObj) {
		$goodsObj = new ome_rpc_response_goods();
		$response = kernel::single('base_rpc_service');
	}

	base_rpc_service::$node_id = $nodeId;

	return $goodsObj->add($sdf, $response);
}

function getShopList() {

	$db = kernel::database();
	$list = $db->select("SELECT * FROM sdb_ome_shop WHERE disabled='false'");
	if ($list) {
		foreach($list as $key => $item) {

			$list[$key]['addon'] = unserialize($item['addon']);
			$list[$key]['config'] = unserialize($item['config']);
		}
		return $list;
	} else {

		return array();
	}
}